#define DEBUG
#include <cstdio>
#define MAXN 50000

using namespace std;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

class Info {
public:
  int a, b, ans;

  Info() {
    a=b=ans=0;
  }
};

class SegmentTree {
public:
  Info n[8*MAXN+1];

  virtual void update(Info a, Info b, Info *c)=0;

  void addA(int o, int l, int r, int t, int v) {
    if (l==r) {
      n[o].a+=v;
    } else {
      int mid=(l+r)/2;
      if (t<=mid) {
	addA(o*2, l, mid, t, v);
      } else {
	addA(o*2+1, mid+1, r, t, v);
      }
      update(n[o*2], n[o*2+1], &n[o]);
    }
  }

  void addB(int o, int l, int r, int t, int v) {
    if (l==r) {
      n[o].b+=v;
    } else {
      int mid=(l+r)/2;
      if (t<=mid) {
	addB(o*2, l, mid, t, v);
      } else {
	addB(o*2+1, mid+1, r, t, v);
      }
      update(n[o*2], n[o*2+1], &n[o]);
    }
  }

  Info get(int o, int l, int r, int tl, int tr) {
    if (l==tl && r==tr) {
      return n[o];
    } else {
      int mid=(l+r)/2;
      Info ret;
      if (tl<=mid && tr>=l) {
	update(ret, get(o*2, l, mid, max(l, tl), min(mid, tr)), &ret);
      }
      if (tl<=r && tr>mid) {
	update(ret, get(o*2+1, mid+1, r, max(mid+1, tl), min(r, tr)), &ret);
      }
      return ret;
    }
  }
};

class SgtA : public SegmentTree {
public:
  void update(Info a, Info b, Info *c) {
    int t=min(a.a, b.b);
    c->ans = a.ans+b.ans+t;
    c->a = a.a+b.a-t;
    c->b = a.b+b.b-t;
  }
};

class SgtB : public SegmentTree {
public:
  void update(Info a, Info b, Info *c) {
    int t=min(a.b, b.a);
    c->ans = a.ans+b.ans+t;
    c->a = a.a+b.a-t;
    c->b = a.b+b.b-t;
  }
};

int main() {
#ifdef DEBUG
  freopen("4684.in", "r", stdin);
  freopen("4684.out", "w", stdout);
#endif

  static SgtA sgta;
  static SgtB sgtb;
  static int a[MAXN+1], b[MAXN+1];
  static bool book[2*MAXN+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", a+i);
    book[a[i]] = true;
    sgtb.addA(1, 1, 2*n, a[i], 1);
  }
  for (int i=2*n; i>0; i--) {
    if (!book[i]) {
      b[++b[0]] = i;
      sgtb.addB(1, 1, 2*n, i, 1);
    }
  }

  int ans=sgtb.get(1, 1, 2*n, 1, 2*n).ans;
  for (int i=1; i<=n; i++) {
    sgtb.addA(1, 1, 2*n, a[i], -1);
    sgtb.addB(1, 1, 2*n, b[i], -1);
    sgta.addA(1, 1, 2*n, a[i], 1);
    sgta.addB(1, 1, 2*n, b[i], 1);
    ans = max(ans, sgta.get(1, 1, 2*n, 1, 2*n).ans+sgtb.get(1, 1, 2*n, 1, 2*n).ans);
  }

  printf("%d", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
